{% include "../public/min-header.html" %}
<div class="wrapper">
	{% include "../public/breadcrumb.html" %}
	<section class="content">
		<div class="row">
			<div class="col-xs-12">
				<div class="box">
					<div class="box-header">
						<nav class="navbar navbar-default">				
	               			<div class="pull-right navbar-form">
	               				<label><a class="btn btn-block btn-primary" href="javascript:void(0)" id="add-menu" data-url="">添加导航菜单</a></label>
	               			</div>
	               		</nav>
					</div>
	               	<div class="box-body">
			           	<div class="row">
			            	<div class="col-sm-12">
				              	<table id="list-table" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
				                 	<thead>
					                   	<tr role="row">
					                   	   	<th>ID</th>  
						                   	<th class="sorting" tabindex="0" aria-controls="example1" >标题</th>
						                   	<th class="sorting" tabindex="0" aria-controls="example1" >排序</th>
						                   	<th class="sorting" tabindex="0" aria-controls="example1" >操作</th>
					                   	</tr>
				                 	</thead>
									<tbody>
										{% for v in tree %}
                                            {% if v %}
											<tr id="mod-{$v.mod_id}">
												<td>{{v.mod_id}}</td>
												<td style="text-align:left;">&nbsp;&nbsp;<strong>{{v.title}}</strong></td>
												<td>
	                                                <input type="text" name="orderby[{{v.mod_id}}]" value="{{v.orderby}}" class="input-sm orderby" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" data-id="{{v.mod_id}}"/>
	                                            </td>
												<td>
													<a href="javascript:void(0)" data-url="{{helper.pathFor('adstctm',{mod_id:v.mod_id,act:'add'})}}" class="btn btn-primary create-sub-menu">添加菜单</a>
													<a href="javascript:void(0)" data-url="{{helper.pathFor('adstctm',{mod_id:v.mod_id,act:'edit'})}}" class="btn btn-info create-sub-menu">编辑</a>
													<a href="javascript:void(0)" data-post-url="{{helper.pathFor('adcoset')}}"  data-id="{{v.mod_id}}" class="btn btn-danger setRemove" data-jump-url="{{helper.pathFor('adstmn')}}" data-type="menu">删除</a>
												 </td>
											</tr>
											{% for vv in v.menu %}
										        {% if vv %}
											<tr id="mod-{$vv.mod_id}">
												<td>{{vv.mod_id}}</td>
												<td style="text-align:left;">&nbsp;&nbsp;|----<strong>{{vv.title}}</strong></td>
												<td>
													<input type="text" name="orderby[{{vv.mod_id}}]" value="{{vv.orderby}}" class="input-sm orderby" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" data-id="{{vv.mod_id}}"/>
												</td>
												<td>
												<a href="javascript:void(0)" class="btn btn-default model-edit" data-url="{{helper.pathFor('adstcld',{mod_id:vv.mod_id})}}">控制模块</a>
												<a href="javascript:void(0)" class="btn btn-info create-sub-menu" data-url="{{helper.pathFor('adstctm',{mod_id:vv.mod_id,act:'edit'})}}">编辑</a>
												<a href="javascript:void(0)" data-post-url="{{helper.pathFor('adcoset')}}" data-id="{{vv.mod_id}}" class="btn btn-danger setRemove" data-jump-url="{{helper.pathFor('adstmn')}}" data-type="menu">删除</a>
												</td>										
											</tr>
                                                {% endif %}
											{% endfor %}
                                            {% endif %}
										{% endfor %}
				                  	</tbody>
				               	</table>
			               	</div>
			          	</div>
	          		</div>
				</div>
			</div>
		</div>
	</section>
</div>
<style type="text/css">
	.table-bordered td{text-align: center;}
</style>
<script>
$('#add-menu').click(function(){
    layer.open({
        type: 2,
        title: '添加导航',
        shadeClose: true,
        shade: 0.8,
        area: ['450px', '320px'],
        content: "{{helper.pathFor('adstctm',{act:'add'})}}",
    });
});

//管理菜单
$('.create-sub-menu').click(function(){
    var url = $(this).attr('data-url');
    layer.open({
        type: 2,
        title: '管理菜单',
        shadeClose: true,
        shade: 0.8,
        area: ['450px', '320px'],
        content: url, 
    });
});

//控制模块
$('.model-edit').click(function(){
    var url = $(this).attr('data-url');
    layer.open({
        type: 2,
        title: '管理模块',
        shadeClose: true,
        shade: 0.8,
        area: ['80%', '70%'],
        content: url, 
    });
});

//回调函数
function call_back(msg){
	if(msg>0){
		layer.msg('操作成功', {icon: 1});
		layer.closeAll('iframe');
		window.location.reload();
	}else{
		layer.msg('操作失败', {icon: 3});
		layer.closeAll('iframe');
	}
}

$('.orderby').blur(function() {
    const post_url = "{{helper.pathFor('adstmn')}}";
    const id = $(this).attr('data-id');
    const orderby = $(this).val();
    const _csrf = "{{ ctx.csrf | safe }}";
    $.ajax({
        type: 'POST',
        url: post_url,
        data: {id, orderby, _csrf},
        dataType: 'JSON',
        success(result) {
            return layer.msg(result.message);
        },
    });
});
</script>

{% include "../public/main-footer.html" %}